package map;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by fengliejv on 2017/10/27.
 */
public class IsomorphicStrings205 {

    public boolean isIsomorphic(String s, String t) {
        if(s.length()!=t.length()){
            return false;
        }
        Map<Character,Character>  st = new HashMap<>();
        Map<Character,Character>  ts = new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            Character ss = s.charAt(i);
            Character tt = t.charAt(i);
            if(st.containsKey(ss)&&st.get(ss)!=tt){
                return false;
            }
            if(ts.containsKey(tt)&&ts.get(tt)!=ss){
                return false;
            }
            st.put(ss,tt);
            ts.put(tt,ss);
        }
        return true;
    }
}
